﻿#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <ctime>
#include <random>
using namespace std;
namespace LittleGame{
	typedef unsigned char uint8_t;

	class Position{
	public:
		uint8_t x,y;
		bool operator==(Position other){
			return this->x==other.x && this->y ==other.y;
		}
	};

	class Enemy{
	private:
		Position _position;

	public:
		Enemy(){
			_position.x=0;
			_position.y=0;
		}
		Position GetPosition(){
			return _position;
		}
		void SetPosition(uint8_t x, uint8_t y){
			_position.x = x;
			_position.y = y;
		}
	};
	class Player{
	private:
		Position _position;
		uint8_t _sightRadius;
		uint8_t _health;
	public:
		Player(){
			_position.x=12;
			_position.y=5;
			_sightRadius=3;
			_health=3;
		}

		Position GetPosition(){
			return _position;
		}

		uint8_t GetHealth(){
			return _health;
		}

		bool CanSee(Position position){
			return position.y<_position.y+_sightRadius
				&& position.y>_position.y-_sightRadius
				&& position.x<_position.x+_sightRadius*1.5
				&& position.x>_position.x-_sightRadius*1.5;
		}

		void SetPosition(Position position){
			_position=position;
		}
	};
	class MainClass{
	private:
		Player _player;
		uint8_t _numberOfEnemies;
		vector<Enemy> _enemies;
		void DrawHealth(){
			cout << "Health: ";
			for(int i=0;i<_player.GetHealth();i++){
				cout << "\x03";
			}
			cout << endl << endl;
		}
		void DrawMap(){
			Position playerPosition = _player.GetPosition();
			for(uint8_t y=0;y<15;y++){
				for(uint8_t x=0;x<25;x++){
					Position position;
					position.x=x;
					position.y=y;
					if(position.x==playerPosition.x && position.y==playerPosition.y){
						cout << "\x01"; //0x07 = beep :)
					}else if(_player.CanSee(position)){
						bool hasEnemy=false;
						for(uint8_t i=0;i<_enemies.size();i++){
							if(position==_enemies[i].GetPosition()){
								hasEnemy=true;
							}
						}
						if(hasEnemy){
							cout << "\x02";
						}else{
							cout << "\xb2";
						}
					}else if(!_player.CanSee(position)){
						cout << "\xb0";
					}
				}
				cout << endl;
			}
		}
	public:
		MainClass(){
			_numberOfEnemies=8;
			srand(time(NULL));
			for(uint8_t i=0; i< _numberOfEnemies;i++){
				Enemy *enemy = new Enemy();
				(*enemy).SetPosition(rand()%15-1, rand()%25-1);
				_enemies.push_back(*enemy);
			}
		}
		void Main(vector<string> args){
			DrawHealth();
			DrawMap();
		}
	};

}

//Entry point, structure arguments into vector and pass it to the main object
int main(int argc, char* args[]){
	vector<string> strArgs;
	for(int i=0;i<argc;i++){
		strArgs.push_back(args[i]);
	}
	LittleGame::MainClass mainObject;
	mainObject.Main(strArgs);
	
	system("PAUSE");
}